home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
dgsay.exe
/
lha
/
DGSTR.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1989-06-29
|
23KB
|
791 lines
{
╔═════════════════════════════════════════════════════════════════════════╗
║ ║
║ TITLE : DGSTR.TPU, Version 8907.01 ║
║ PURPOSE : String Object and String Handling Routines ║
║ AUTHOR : David Gerrold, CompuServe ID: 70307,544 ║
║ _____________________________________________________________________ ║
║ ║
║ Written in Turbo Pascal, Version 5.5, ║
║ with routines from Turbo Professional, Version 5.0. ║
║ ║
║ Turbo Pascal is a product of Borland International. ║
║ Turbo Professional is a product of TurboPower Software ║
║ _____________________________________________________________________ ║
║ ║
║ This is not public domain software. This is shareware. ║
║ This software is copyright 1989, by David Gerrold. ║
║ ║
║ The Brass Cannon Corporation ║
║ 9420 Reseda Blvd., #804 ║
║ Northridge, CA 91324-2932. ║
║ ║
║ If you find this code useful, a donation of $25 is requested -- ║
║ not to me, but to the AIDS Project Los Angeles. Donations may ║
║ be forwarded via the Brass Cannon address. Thank you. ║
║ ║
╚═════════════════════════════════════════════════════════════════════════╝
}
{ ========================================================================= }
{ Compiler Directives : }
{ ========================================================================= }
{$R-} {Range checking off}
{$B+} {Boolean complete evaluation on}
{$S+} {Stack checking on}
{$I+} {I/O checking on}
{$N+,E+} {Simulate numeric coprocessor}
{$M 65500,16384,655360} {Turbo 3 default stack and heap}
{$V-} {Variable range checking off}
{ ========================================================================= }
UNIT DgStr;
{ ========================================================================= }
INTERFACE
USES
TpString, { Turbo Power unit }
DgInit; { Dg Initializations }
TYPE
StrOb = Object (LocOb)
S : string;
Procedure AcceptStr (NewStr : string);
Procedure AcceptRaw (RawStr : string);
Procedure UpStr;
Procedure LoStr;
Procedure UpCaseFirstLetter;
Procedure TrimLeadCh (Ch : char);
Procedure TrimTrailCh (Ch : char);
Procedure TrimCh (Ch : char);
Procedure StripOut (Ch : char);
Procedure OverWrite (Position : byte; OverStr : string);
Procedure Replace (OldStr, NewStr : string);
Procedure Translate (OldCh, NewCh : char);
Procedure Append (NewStr : string);
Procedure AppendWord (NewStr : string);
Procedure HeadAppend (NewStr : string);
Procedure Compress;
Procedure DeCompress;
Function L : byte;
Function LastPos (PosCh : char) : byte;
Function SubStr (Pos1, Pos2 : byte) : string;
Function ExtractFirstWord : string;
Function TrimThe : string;
end;
{ ========================================================================= }
FUNCTION TrimLeadChars (S : string; Ch : char) : string;
{ Trims all occurrences of Ch from the beginning of a string. }
FUNCTION TrimTrailChars (S : string; Ch : char) : string;
{ Trims all occurrences of Ch from the end of a string. }
FUNCTION TrimChars (S : string; Ch : char) : string;
{ Trims all occurrences of Ch from the beginning and end of a string. }
FUNCTION InCap (Ch : char) : boolean;
{ Returns true if letter is upper case. }
FUNCTION Capitalize (S : string) : string;
{ Capitalizes the first letter in the string. }
FUNCTION CapitalizeAll (S : string) : string;
{ Capitalizes every word in the string. }
PROCEDURE ReplaceOnce (Var S : string; OldStr, NewStr : string);
{ Finds OldStr in S and replaces it with NewStr. }
PROCEDURE ReplaceAll (Var S : string; OldStr, NewStr : string);
{ Replaces all occurrences of OldStr with NewStr. }
FUNCTION GetSubStr (S : string; Pos1, Pos2 : byte) : string;
{ Extracts a SubString, starting at Pos1, ending at Pos2. }
FUNCTION Num2Str (Num : extended) : string;
{ Returns any number in shortest possible string. }
FUNCTION Str2Num (S : string) : real;
{ Turns a number in a string into a real number. }
FUNCTION InAlphabet (Ch : char) : boolean;
{ Returns true if ch in Alphabet. }
FUNCTION InNumbers (Ch : char) : boolean;
{ Returns true if ch is a number. }
FUNCTION InApostrophe (Ch : char) : boolean;
{ Returns true if ch is apostrophe. }
FUNCTION InTwoSpacePunctuation (Ch : char) : boolean;
{ Returns true if ch in two space punctuation. }
FUNCTION InPunctuation (Ch : char) : boolean;
{ Returns true if ch in punctuation. }
{ ========================================================================= }
{ ========================================================================= }
IMPLEMENTATION
{ ========================================================================= }
FUNCTION TrimLeadChars (S : string; Ch : char) : string;
{
Trims all occurrences of Ch from the beginning of S.
}
VAR
Len : byte absolute S;
BEGIN
While
(S [1] = Ch) and (Len > 0) { while S [1] = Ch }
do
begin
dec (Len); { shorten S }
move (S [2], S [1], Len); { delete 1st char }
end;
TrimLeadChars := S; { return }
END;
{ ========================================================================= }
FUNCTION TrimTrailChars (S : string; Ch : char) : string;
{
Trims all occurrences of Ch from the end of S.
}
VAR
Len : byte absolute S;
BEGIN
While
(S [Len] = Ch) { while last char = Ch }
do
dec (Len); { shorten S }
TrimTrailChars := S; { return }
END;
{ ========================================================================= }
FUNCTION TrimChars (S : string; Ch : char) : string;
{
Trims all occurrences of Ch from both the beginning and end of S.
}
BEGIN
TrimChars := TrimTrailChars (TrimLeadChars (S, Ch), Ch);
END;
{ ========================================================================= }
PROCEDURE StrOb.AcceptStr (NewStr : string);
{
Accept a new string into S.
}
BEGIN
S := NewStr;
END;
{ ========================================================================= }
PROCEDURE StrOb.AcceptRaw (RawStr : String);
{
Takes raw variable strings, such as those found in Turbo Pascal code,
and converts them to standard text strings.
Will translate #39 into ' and ^E into Ctrl-E, etc.
Useful for translating text strings from files. No real
error-trapping here. Routine tends to ignore what it doesn't
understand. Nevertheless, use with caution. Make sure input
strings are valid or results may be unpredictable.
}
VAR
LenRawStr : byte absolute RawStr;
Loop : byte;
NumStr : string [2];
Trash : word;
Ch : char;
BEGIN
Loop := 1;
S := '';
While
Loop <= LenRawStr
Do
Begin
Case RawStr [Loop] of
'^' : begin